#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution {
public:
    string reverseWords(string s) {
        if(s.empty()){
            return s;
        }
        int i = 0;
        string temp = "";
        int status = 0;
        while(i<s.size()){
            if(status == 0&&s[i]==' '){
                
            }
            else if(s[i]!=' '){
                temp += s[i];
                status = 1;
            }
            else if(status==1&&s[i]==' '){
                break;
            }
            ++i;
        }
        string result =reverseWords(string(s.begin()+i,s.end()));
        if(result.empty())
            return temp;
        else{
            return result +" "+temp;
        }
    }
};

int main(){
    Solution S;
    cout<<S.reverseWords("a good   example")<<endl;
}

